package yxy.game.pm2.command.plainsCraft;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlainsCraftMessage;
import yxy.game.pm2.module.plainsCraft.PlainsCraftHandle;

import java.util.Date;

/** 中原争霸 中原争霸选手信息 */
@MessageType(proto = Command.PlainsCraftPlayerInfo, classtype = PlainsCraftMessage.PlainsCraftPlayerInfoRequest.class)
public class CMD_PlainsCraftPlayerInfo extends Command<PlainsCraftMessage.PlainsCraftPlayerInfoRequest> {

	@Override
	public void execute(MessageSource messageSource, PlainsCraftMessage.PlainsCraftPlayerInfoRequest request) {
		Date date = new Date();

		String playerCode = messageSource.getTag();
		int rank = request.getRank();
		int level = request.getLevel();

		PlainsCraftMessage.PlainsCraftPlayerInfoResponse.Builder response = PlainsCraftMessage.PlainsCraftPlayerInfoResponse.newBuilder();

		Result result = new PlainsCraftHandle().rankInfo(playerCode, rank, level, response);

		send(messageSource, response, result);

		Date date1 = new Date();
		System.out.println("CMD_PlainsCraftPlayerInfo:"+(date1.getTime()-date.getTime()));

	}

	private void send(MessageSource messageSource, PlainsCraftMessage.PlainsCraftPlayerInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}